import { createStore } from "vuex"
import http from "../utils/http";

export default createStore({
  state: {
    //科目 dictType
    dictTypeForSubject: "subject_type",
    //数据字典
    dictData: [],
    preferenceSetting: {
      subjectId: '',
      subjectName: ''
    }
  },
  modules: {
    // user
  },

  mutations: {
    // 重置vuex本地储存状态
    updateState(state, payload) {
      Object.keys(payload).forEach((key) => {
        state[key] = payload[key];
      });
    }
  },

  actions: {
    updateState(ctx, { payload }) {
      ctx.commit("updateState", payload);
    },
    initApp(ctx) {
      console.log(this.state.dictTypeForSubject)
      return Promise.all([
        http.get('/education/dict/data/list',{params: { dictType: this.state.dictTypeForSubject}}) //加载字典
      ]).then(([dictData]) => {
        ctx.commit("updateState", {
          dictData: dictData.data.data || []
        });
      });
    },
  }
})
